<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="ID" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机器人" prop="Robot">
        <el-input
          v-model="queryParams.robot"
          placeholder="请输入机器人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规范号" prop="gaugeNumber">
        <el-input
          v-model="queryParams.gaugeNumber"
          placeholder="请输入规范号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电极形式" prop="electrodeForm">
        <el-input
          v-model="queryParams.electrodeForm"
          placeholder="请输入电极形式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="材质1" prop="material1">
        <el-input
          v-model="queryParams.material1"
          placeholder="请输入材质1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="材质1厚度(mm)" prop="materialThickness1">
        <el-input
          v-model="queryParams.materialThickness1"
          placeholder="请输入材质1厚度(mm)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="涂胶1" prop="gumming1">
        <el-input
          v-model="queryParams.gumming1"
          placeholder="请输入涂胶1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="材质2" prop="material2">
        <el-input
          v-model="queryParams.material2"
          placeholder="请输入材质2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="材质2厚度(mm)" prop="materialThickness2">
        <el-input
          v-model="queryParams.materialThickness2"
          placeholder="请输入材质2厚度(mm)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="涂胶2" prop="gumming2">
        <el-input
          v-model="queryParams.gumming2"
          placeholder="请输入涂胶2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="材质3" prop="material3">
        <el-input
          v-model="queryParams.material3"
          placeholder="请输入材质3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="材质3厚度(mm)" prop="materialThickness3">
        <el-input
          v-model="queryParams.materialThickness3"
          placeholder="请输入材质3厚度(mm)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="涂胶3" prop="gumming3">
        <el-input
          v-model="queryParams.gumming3"
          placeholder="请输入涂胶3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="材质4" prop="material4">
        <el-input
          v-model="queryParams.material4"
          placeholder="请输入材质4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="材质4厚度(mm)" prop="materialThickness4">
        <el-input
          v-model="queryParams.materialThickness4"
          placeholder="请输入材质4厚度(mm)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="压力(N)" prop="stress">
        <el-input
          v-model="queryParams.stress"
          placeholder="请输入压力(N)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预压时间(ms)" prop="preloadingTime">
        <el-input
          v-model="queryParams.preloadingTime"
          placeholder="请输入预压时间(ms)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预热时间(ms)" prop="preheatingTime">
        <el-input
          v-model="queryParams.preheatingTime"
          placeholder="请输入预热时间(ms)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预热电流(kA)" prop="preheatingCurrent">
        <el-input
          v-model="queryParams.preheatingCurrent"
          placeholder="请输入预热电流(kA)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="冷却时间(ms)" prop="coolingTime">
        <el-input
          v-model="queryParams.coolingTime"
          placeholder="请输入冷却时间(ms)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="递增时间(ms)" prop="incrementalTime">
        <el-input
          v-model="queryParams.incrementalTime"
          placeholder="请输入递增时间(ms)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="起始电流(KA)" prop="startingCurrent">
        <el-input
          v-model="queryParams.startingCurrent"
          placeholder="请输入起始电流(KA)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="焊接时间(ms)" prop="weldingTime">
        <el-input
          v-model="queryParams.weldingTime"
          placeholder="请输入焊接时间(ms)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="焊接电流(kA)" prop="weldingCurrent">
        <el-input
          v-model="queryParams.weldingCurrent"
          placeholder="请输入焊接电流(kA)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="冷却时间(ms)" prop="coolingTime1">
        <el-input
          v-model="queryParams.coolingTime1"
          placeholder="请输入冷却时间(ms)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="递减时间(ms)" prop="declineTime">
        <el-input
          v-model="queryParams.declineTime"
          placeholder="请输入递减时间(ms)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="终止电流(KA)" prop="terminationCurrent">
        <el-input
          v-model="queryParams.terminationCurrent"
          placeholder="请输入终止电流(KA)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="脉冲次数" prop="pulseFrequency">
        <el-input
          v-model="queryParams.pulseFrequency"
          placeholder="请输入脉冲次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="冷却时间(ms)" prop="coolingTime2">
        <el-input
          v-model="queryParams.coolingTime2"
          placeholder="请输入冷却时间(ms)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="回火时间(ms)" prop="temperingTime">
        <el-input
          v-model="queryParams.temperingTime"
          placeholder="请输入回火时间(ms)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="回火电流(kA)" prop="temperingCurrent">
        <el-input
          v-model="queryParams.temperingCurrent"
          placeholder="请输入回火电流(kA)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="保持时间(ms)" prop="holdTime">
        <el-input
          v-model="queryParams.holdTime"
          placeholder="请输入保持时间(ms)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="参数形式" prop="parametricForm">
        <el-input
          v-model="queryParams.parametricForm"
          placeholder="请输入参数形式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['DataRB:dataRB:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="handleClear"
          v-hasPermi="['DataRB:dataRB:clear']"
        >清空数据</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['DataRB:dataRB:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="weldList"
      @selection-change="handleSelectionChange"
      border
      style="width: 100%;"
      :show-overflow-tooltip="true"
      empty-text="暂无数据"
    >

      <el-table-column type="selection" align="center" width="55"></el-table-column>
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="焊点号" align="center" prop="sjNumber" />
      <el-table-column label="机器人" align="center" prop="robot" />
      <el-table-column label="规范号" align="center" prop="gaugeNumber" />
      <el-table-column label="电极形式" align="center" prop="electrodeForm" />
      <el-table-column label="材质1" align="center" prop="material1" />
      <el-table-column label="材质1厚度(mm)" align="center" prop="materialThickness1" />
      <el-table-column label="涂胶1" align="center" prop="gumming1" />
      <el-table-column label="材质2" align="center" prop="material2" />
      <el-table-column label="材质2厚度(mm)" align="center" prop="materialThickness2" />
      <el-table-column label="涂胶2" align="center" prop="gumming2" />
      <el-table-column label="材质3" align="center" prop="material3" />
      <el-table-column label="材质3厚度(mm)" align="center" prop="materialThickness3" />
      <el-table-column label="涂胶3" align="center" prop="gumming3" />
      <el-table-column label="材质4" align="center" prop="material4" />
      <el-table-column label="材质4厚度(mm)" align="center" prop="materialThickness4" />
      <el-table-column label="压力(N)" align="center" prop="stress" />
      <el-table-column label="预压时间(ms)" align="center" prop="preloadingTime" />
      <el-table-column label="预热时间(ms)" align="center" prop="preheatingTime" />
      <el-table-column label="预热电流(kA)" align="center" prop="preheatingCurrent" />
      <el-table-column label="冷却时间(ms)" align="center" prop="coolingTime" />
      <el-table-column label="递增时间(ms)" align="center" prop="incrementalTime" />
      <el-table-column label="起始电流(KA)" align="center" prop="startingCurrent" />
      <el-table-column label="焊接时间(ms)" align="center" prop="weldingTime" />
      <el-table-column label="焊接电流(kA)" align="center" prop="weldingCurrent" />
      <el-table-column label="冷却时间(ms)" align="center" prop="coolingTime1" />
      <el-table-column label="递减时间(ms)" align="center" prop="declineTime" />
      <el-table-column label="终止电流(KA)" align="center" prop="terminationCurrent" />
      <el-table-column label="脉冲次数" align="center" prop="pulseFrequency" />
      <el-table-column label="冷却时间(ms)" align="center" prop="coolingTime2" />
      <el-table-column label="回火时间(ms)" align="center" prop="temperingTime" />
      <el-table-column label="回火电流(kA)" align="center" prop="temperingCurrent" />
      <el-table-column label="保持时间(ms)" align="center" prop="holdTime" />
      <el-table-column label="参数形式" align="center" prop="parametricForm" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['DataRB:dataRB:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>

    <el-dialog :title="Export.title" :visible.sync="Export.open" width="400px" append-to-body>
      <span>是否导出全部数据</span>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ExportAll">确 定</el-button>
        <el-button @click="Export.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDataRB, getDataRB, delDataRB } from "@/api/WELD/dataRB";
import { getToken } from "@/utils/auth";
import axios from "axios";

export default {
  name: "DataRB",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 唯一标识符
      uniqueId: "",
      // 选中数组
      ids: [],
      // 菜单列表
      menuOptions: [],
      // 存储用户选择的数据项
      multipleSelection: [],
      // 选中表数组
      tableNames: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch:false,
      // 总条数
      total: 0,
      // 表数据
      weldList: [],
      // 日期范围
      dateRange: "",
      // 部门树选项
      deptOptions: undefined,
      // 是否显示弹出层
      open: false,
      // 弹出层标题
      title: "",
      // 表单参数
      form: {},

      defaultProps: {
        children: "children",
        label: "label"
      },

      // 导出参数
      Export:{
        // // 是否显示弹出层
        open: false,
        // // 弹出层标题
        title: "",
      },

      queryParams: {
        pageNum: 1,
        pageSize: 50,
        ipaddr: undefined,
        name:undefined,
        tableName: undefined,
        tableComment: '' // 假设这是下拉列表绑定的模型
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listDataRB(this.queryParams).then(response => {
        this.weldList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
      this.multipleSelection =selection;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const Ids = row.ID || this.ids;
      let displayIds=Ids;
      if (Ids.length>10){
        displayIds=Ids.slice(0,10)+"...";
      }
      this.$modal.confirm('是否确认删除编号为"' + displayIds + '"的数据项？').then(function() {
        return delDataRB(Ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 清空 */
    handleClear(){
      this.$modal.confirm('是否确认清空所有数据项？').then(() =>{
        axios.delete('/dev-api/DataRB/dataRB/clear',{
          headers: {
            // 将 token 添加到请求头中，通常是 'Authorization' 头
            'Authorization': `Bearer ${getToken()}`
          }
        }).then(response =>{
          this.$modal.msgSuccess("清空成功！");
          this.getList();
        }).catch(err=>{
          this.$modal.msgError("清空失败：" + error.message);
        });
      }).catch(() => {});
    },

    /** 导出按钮操作 */
    handleExport() {
      if (this.multipleSelection.length===0){
        this.Export.title = "数据导入";
        this.Export.open = true;
      }else {
        const ids = this.multipleSelection.map(item => item.id).join(',');
        this.download('DataRB/dataRB/export', {ids}, `weld_${new Date().getTime()}.xlsx`)
      }
    },
    ExportAll(){
      this.download('DataRB/dataRB/exportAll',1,`weld_${new Date().getTime()}.xlsx`);
      this.Export.open = false;
    },

  }
};
</script>
